#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif

#include "fx.h"
#include "FXTranslate.h"

/****************************************
 * show FXTranslate use :
 * - load the translation file on startup
 * - call tr() on each text. 
 *    this function is defined in FXWindow.
 *****************************************/


class DirListWindow : public FXMainWindow 
{
	FXDECLARE(DirListWindow)
protected:
	FXMenuBar*         menubar;
	FXMenuPane*        filemenu;
	FXDirList*         contents;
	FXTextField*       text;
protected:
	DirListWindow(){}
public:
	DirListWindow(FXApp* a);
	virtual void create();
	virtual ~DirListWindow();
};

FXIMPLEMENT(DirListWindow, FXMainWindow, NULL, 0)


DirListWindow::DirListWindow(FXApp* a):FXMainWindow(a,"",NULL,NULL,DECOR_ALL,0,0,800,600)
{
	setTitle(tr("Directory List"));
	
	// Make menu bar
	menubar=new FXMenuBar(this,LAYOUT_FILL_X);
	filemenu=new FXMenuPane(this);
	new FXMenuCommand(filemenu, tr("Quit\tCtl-Q"),NULL,getApp(),FXApp::ID_QUIT);
	new FXMenuTitle(menubar,tr("File"),NULL,filemenu);

	// Text field at bottom
	text=new FXTextField(this,10,NULL,0,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|FRAME_SUNKEN|FRAME_THICK);

	// Make contents
	contents=new FXDirList(this,NULL,0,HSCROLLING_OFF|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|TREELIST_BROWSESELECT|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0);

	text->setTarget(contents);
	text->setSelector(FXWindow::ID_SETVALUE);
}


DirListWindow::~DirListWindow()
{
	delete filemenu;
}


void DirListWindow::create()
{
	FXMainWindow::create();
	show(PLACEMENT_SCREEN);
}


/*******************************************************************************/
int main(int argc,char *argv[])
{
	FXApp application("DirList","FoxTest");
	application.init(argc,argv);

	// load translation on startup
	FXTranslate translate(&application);
	if (!translate.load("./French.txt"))
		printf("Unabled to open traduction\n");
	else
		application.setTranslator(&translate);

	new DirListWindow(&application);

	application.create();

	// Run
	return application.run();
}


